/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number}
 */
 var minDepth = function(root) {
    let res=0,sum=0;
    if(!root) return res
    let queue = [root]
    while(queue.length){
       res++
        let length =queue.length
        for(let i=0;i<length;i++){
            let node = queue.shift()
            //如果左右节点都是null才代表是最小深度
            if(node.left==null&&node.right==null) return res
            node.left&&queue.push(node.left)
            node.right&&queue.push(node.right)
        }
        
    }
    return res
};